<?php
// This class was created for the purpose of being able to browse a user's friend's cards in order to select them to propose a trade
// Currently a lot of copied code from getCardList.php
// Author - Kevin Johnstone 
require_once('../utils/query.php');
require_once ('utils/logged_in.php'); // not sure if these are necessary

$friendFbID = $_POST['friendFbID']; // Will be used to grab friends drupal ID to match up with possession table

// Find the drupal id corresponding with the facebook id of the person to trade with
$friendDrupalID = execute_query("SELECT drupaluid FROM facebookUser WHERE facebookID='%s'", $friendFbID);
$friendDrupalID  = mysql_result($friendDrupalID , 0);
/* Will look at the Possession table and cards_lu table. Selecting the full_id, type, name, and card_img from the cards_lu table that match the users
cards they own based on possession id equaling the card's full id based on the possession table knowing the friendsDrupalID
*/

$friendCards = execute_query("SELECT full_id, name, card_img, type, possessionid FROM cards_lu INNER JOIN Possession ON Possession.cardid=cards_lu.full_id WHERE front IS NULL AND userid ='%s'", $friendDrupalID);
?> 
<!--<ul class="cards">-->
<ul>
	<?php
		while ($row = mysql_fetch_array($friendCards))
		{
			$cardid = $row[0]; // check
			$name = $row[1];
			$card_img = $row[2];
			$type = $row[3];
			
			$name = str_replace(array(' 11', ' 7', ' 3', ' 2', ' 4'), array(' 9', ' 5', ' 1', ' 1', ' 2'), $name);
			
			$color = "#ffffff";
			if ($type == 1)
				$color = "#dc3122";
			else if ($type == 2)
				$color = "#ddd327";
			else if ($type == 3)
				$color = "#0145f3";
			else if ($type == 10)
				$color = "#653b67";
				
			if(strlen($name) > 16)
			$showname = substr ($name,0,16) . "...";
			else
			$showname = $name;
	?>
	
			<!-- '..' represents the parent directory. Images are being pulled of the ftp server -->
			<li class="card" id="<?php echo($cardid); ?>">
				<div class="cardImg">
					<img src="../../../card_imgs/<?php echo($card_img); ?>"> 
				</div>
				<!--<div class="cardDesc" style="background:<?php echo($color); ?>;">-->
				<div class="cardDesc" title="<?php echo($name); ?>">
					<?php echo($showname); ?>
				</div>
			</li>
	<?php
		}
	?>
</ul>